package com.jobLink.postings.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jobLink.common.annotation.Log;
import com.jobLink.common.core.controller.BaseController;
import com.jobLink.common.core.domain.AjaxResult;
import com.jobLink.common.enums.BusinessType;
import com.jobLink.postings.domain.JobPostings;
import com.jobLink.postings.service.IJobPostingsService;
import com.jobLink.common.utils.poi.ExcelUtil;
import com.jobLink.common.core.page.TableDataInfo;

/**
 * 岗位信息Controller
 * 
 * @author dane
 * @date 2025-03-10
 */
@RestController
@RequestMapping("/postings/postings")
public class JobPostingsController extends BaseController
{
    @Autowired
    private IJobPostingsService jobPostingsService;

    /**
     * 查询岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:list')")
    @GetMapping("/list")
    public TableDataInfo list(JobPostings jobPostings)
    {
        startPage();
        List<JobPostings> list = jobPostingsService.selectJobPostingsList(jobPostings);
        return getDataTable(list);
    }

    /**
     * 导出岗位信息列表
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:export')")
    @Log(title = "岗位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JobPostings jobPostings)
    {
        List<JobPostings> list = jobPostingsService.selectJobPostingsList(jobPostings);
        ExcelUtil<JobPostings> util = new ExcelUtil<JobPostings>(JobPostings.class);
        util.exportExcel(response, list, "岗位信息数据");
    }

    /**
     * 获取岗位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:query')")
    @GetMapping(value = "/{jobId}")
    public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
    {
        return success(jobPostingsService.selectJobPostingsByJobId(jobId));
    }

    /**
     * 新增岗位信息
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:add')")
    @Log(title = "岗位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JobPostings jobPostings)
    {
        return toAjax(jobPostingsService.insertJobPostings(jobPostings));
    }

    /**
     * 修改岗位信息
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:edit')")
    @Log(title = "岗位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JobPostings jobPostings)
    {
        return toAjax(jobPostingsService.updateJobPostings(jobPostings));
    }

    /**
     * 删除岗位信息
     */
    @PreAuthorize("@ss.hasPermi('postings:postings:remove')")
    @Log(title = "岗位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jobIds}")
    public AjaxResult remove(@PathVariable Long[] jobIds)
    {
        return toAjax(jobPostingsService.deleteJobPostingsByJobIds(jobIds));
    }
}
